package com.ruoyi.operator.controller;

import java.util.List;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.operator.mapper.OptShopMemberMapper;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.operator.domain.OptMemberOrderDetail;
import com.ruoyi.operator.service.IOptMemberOrderDetailService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 会员收支记录详情Controller
 * 
 * @author ruoyi
 * @date 2021-01-27
 */
@Controller
@RequestMapping("/operator/detail")
public class OptMemberOrderDetailController extends BaseController {
    private String prefix = "operator/detail";

    @Autowired
    private IOptMemberOrderDetailService optMemberOrderDetailService;
    @Autowired
    private OptShopMemberMapper optShopMemberMapper;
    @RequiresPermissions("operator:detail:view")
    @GetMapping()
    public String detail() {
        return prefix + "/detail";
    }

    /**
     * 查询会员收支记录详情列表
     */
    @RequiresPermissions("operator:detail:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(OptMemberOrderDetail optMemberOrderDetail)
    {
        startPage();
        SysUser currentUser  = (SysUser) SecurityUtils.getSubject().getPrincipal();
        if(!(currentUser.getDeptId() == 100)){ optMemberOrderDetail.setDeptId(currentUser.getDeptId()); }
        List<OptMemberOrderDetail> list = optMemberOrderDetailService.selectOptMemberOrderDetailList(optMemberOrderDetail);
        return getDataTable(list);
    }

    /**
     * 导出会员收支记录详情列表
     */
    @RequiresPermissions("operator:detail:export")
    @Log(title = "会员收支记录详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(OptMemberOrderDetail optMemberOrderDetail)
    {
        List<OptMemberOrderDetail> list = optMemberOrderDetailService.selectOptMemberOrderDetailList(optMemberOrderDetail);
        ExcelUtil<OptMemberOrderDetail> util = new ExcelUtil<OptMemberOrderDetail>(OptMemberOrderDetail.class);
        return util.exportExcel(list, "detail");
    }

    /**
     * 新增会员收支记录详情
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存会员收支记录详情
     */
    @RequiresPermissions("operator:detail:add")
    @Log(title = "会员收支记录详情", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(OptMemberOrderDetail optMemberOrderDetail)
    {
        return toAjax(optMemberOrderDetailService.insertOptMemberOrderDetail(optMemberOrderDetail));
    }

    /**
     * 修改会员收支记录详情
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        OptMemberOrderDetail optMemberOrderDetail = optMemberOrderDetailService.selectOptMemberOrderDetailById(id);
        mmap.put("optMemberOrderDetail", optMemberOrderDetail);
        return prefix + "/edit";
    }

    /**
     * 修改保存会员收支记录详情
     */
    @RequiresPermissions("operator:detail:edit")
    @Log(title = "会员收支记录详情", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(OptMemberOrderDetail optMemberOrderDetail)
    {
        return toAjax(optMemberOrderDetailService.updateOptMemberOrderDetail(optMemberOrderDetail));
    }

    /**
     * 删除会员收支记录详情
     */
    @RequiresPermissions("operator:detail:remove")
    @Log(title = "会员收支记录详情", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(optMemberOrderDetailService.deleteOptMemberOrderDetailByIds(ids));
    }


}
